package de.uni.muenster.idw2.xml;

import java.io.InputStream;
import java.net.URL;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import android.util.Log;
import de.uni.muenster.idw2.data.Building;

public class OFMXMLParser {

//	private final String urlString = "http://dl.dropbox.com/u/4258745/roko.xml";

	
	private String urlString;



	public Building getBuilding(String path){
        
		this.urlString = path;
        OFMXMLHandler xmlHandler = new OFMXMLHandler();
        this.parse(xmlHandler);
        return xmlHandler.getBuilding();
	}
	

	
	private void parse (OFMXMLHandler xmlHandler){
		
		
		 try {
			  
             /* Create a URL we want to load some xml-data from. */

             URL url = new URL(urlString);
             
             /* Get a SAXParser from the SAXPArserFactory. */

             SAXParserFactory spf = SAXParserFactory.newInstance();

             SAXParser sp = spf.newSAXParser();



             /* Get the XMLReader of the SAXParser we created. */

             XMLReader xr = sp.getXMLReader();

             /* Create a new ContentHandler and apply it to the XML-Reader*/



             xr.setContentHandler(xmlHandler);

            

             /* Parse the xml-data from our URL. */

             InputStream is = url.openStream();
             
             xr.parse(new InputSource(is));

             /* Parsing has finished. */
             


     } catch (Exception e) {

             /* Display any Error to the GUI. */

        
             Log.e("wichtig", "WeatherQueryError", e);

     }
		
		
		
	}

}
